package com.example.onlinemusicserver2024.controller;

import com.example.onlinemusicserver2024.common.R;
import com.example.onlinemusicserver2024.model.domain.Comment;
import com.example.onlinemusicserver2024.model.request.UserSupportRequest;
import com.example.onlinemusicserver2024.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CommentController {


    @Autowired
    CommentService commentService;

    /**
     * 根据歌曲id获取评论
     *
     * @param songId
     * @return
     */
    @GetMapping("/comment/song/detail")
    public R getComments(@RequestParam int songId) {
        System.out.println("获取评论，歌曲id=" + songId);
        R result = commentService.getComments(songId);
        return result;
    }

    /**
     * 根据歌单id获取评论
     *
     * @param songListId
     * @return
     */
    @GetMapping("/comment/songList/{songListId}")
    public R getCommentsBySongListId(@PathVariable int songListId) {
        System.out.println("根据歌单id获取评论，id=" + songListId);
        R result = commentService.getCommentsBySongListId(songListId);
        return result;
    }

    /**
     * 获取评论列表
     * @param songListId
     * @return
     */
    @GetMapping("/comment/songList/detail")
    public R getCommentList(@RequestParam int songListId) {
        System.out.println("查询歌单评论列表数据，id=" + songListId);
        R result = commentService.getCommentList(songListId);
        return result;
    }

    /**
     * 发布评论
     * @param comment
     * @return
     */
    @PostMapping("/comment/add")
    public R addComment(@RequestBody Comment comment){
        R result = commentService.addComment(comment);
        return result;
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @GetMapping("/comment/delete")
    public R deleteCommentById(@RequestParam int id){
        R result = commentService.deleteCommentById(id);
        return result;
    }

    /**
     * 点赞
     * @param comment
     * @return
     */
    @PostMapping("/userSupport/like")
    public R userLike(@RequestBody UserSupportRequest userSupportRequest){
        R result = commentService.userLike(userSupportRequest);
        return result;
    }



}
